﻿using CBS.APP;
using CBS.Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CBS.Desktop.FormPage
{
    /// <summary>
    /// EditTeacherSemesterAmount.xaml 的交互逻辑
    /// </summary>
    public partial class EditTeacherSemesterAmount : Window
    {
        private TeacherSemesterAmountViewModel viewModel;

        public EditTeacherSemesterAmount()
        {
            InitializeComponent();
        }

        public EditTeacherSemesterAmount(int StudentSemesterAmountId)
        {
            InitializeComponent();

            viewModel = TeacherApp.GetTeacherSemesterAmountForm(StudentSemesterAmountId);
            tb_TeacherName.Text = viewModel.TeacherName;
            tb_Semester.Text = viewModel.SemesterName;
            tb_Receivable.Text = viewModel.Receivable.ToString();
            tb_Reeipts.Text = viewModel.Reeipts.ToString();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            decimal receivable = 0;
            decimal reeipts = 0;
            bool isEdit = false;

            if (!string.IsNullOrWhiteSpace(tb_Receivable.Text) && decimal.TryParse(tb_Receivable.Text, out receivable))
            {
                viewModel.Receivable = receivable;
                isEdit = true;
            }

            if (!string.IsNullOrWhiteSpace(tb_Reeipts.Text) && decimal.TryParse(tb_Reeipts.Text, out reeipts))
            {
                viewModel.Reeipts = reeipts;
                isEdit = true;
            }

            if (isEdit)
            {
                if (TeacherApp.UpdateTeacherSemesterAmount(viewModel))
                {
                    this.DialogResult = true;
                }
            }
        }
    }
}
